var app = getApp();
var config = require('../../config.js');
var pageIndex = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordList: [],
    nodata:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userFaceUrl: app.globalData.userInfo.avatarUrl,
      nickName: app.globalData.userInfo.nickName
    });
    pageIndex = 1;
    this.myRecordlist();
    this.myrecordlistLabel();
  },

  /**
   * 我的记录
   */
  myRecordlist: function (e) {
    var that = this;
    wx.request({
      url: config.recordList,
      method: "POST",
      data: {
        openId: app.globalData.openid,
        pageSize: 10,
        page: pageIndex
      },
      success: function (res) {
        console.log(config.recordList)
        if (res.data.rows == '' || res.data.rows == null) {
          that.setData({
            nodata:true
          })
        }
        if (res.data.success == 0) {
          if (pageIndex == 1){
            that.setData({
              recordList: res.data.rows,
              firsday:res.data.firstday,
              lastday: res.data.firstday,
            });
            console.log(that.data.recordList)
          }else {
            //加载更多
           var list =  that.data.recordList;
            if(list.length>0){
              for (var i = 0; i < res.data.rows.length; i++) {
                list.push(res.data.rows[i]);
              }
            that.setData({
              recordList: list,
              
            });
            }
          }
        }
      }
    });
  
  },
 
 /**
   *  我的记录标签
   */
  myrecordlistLabel:function(){
    var that=this;
    wx.request({
      url: config.toplistLabel,
      method: "POST",
      data: {
        openId: app.globalData.openid,
      },
      success:function(res){
        console.log(config.toplistLabel)
        if (res.data.success == 0) {
          that.setData({
            labelName: res.data.rows.labelName
          });
        }
      }
    })
  },


  //加载更多
  onReachBottom: function () {
    console.log('加载更多')
    pageIndex++;
    this.myRecordlist();

  }
})